﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CNotebook;

namespace NotebookS2
{
    public partial class InventoryRevaluation : Form
    {
        public InventoryRevaluation()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }

        public DataTable LineItems { get; set; }

        void BindWarehouse()
        {
            WarehouseManager oManager = new WarehouseManager();
            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            DataTable oTable = new DataTable();

            oTable = oManager.GetWarehouse();



            
            cboWarehouse.DataSource = oTable;
            cboWarehouse.DisplayMember = "Dscription";
            cboWarehouse.ValueMember = "Code";
            DevExpress.XtraEditors.Controls.LookUpColumnInfo col;

            col = new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Dscription", "Dscription", 100);

            col.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;

            cboWarehouse.Columns.Add(col);
            cboWarehouse.ShowHeader = false;
            
            oManager.Close();
        }

        public void InitTable()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("WhseCode", typeof(string));
            dt.Columns.Add("ItemCode", typeof(string));
            dt.Columns.Add("ItemName", typeof(string));
            dt.Columns.Add("CurrentCost", typeof(double));
            dt.Columns.Add("NewCost", typeof(double));

            this.LineItems = dt;
        }

        private void InventoryRevaluation_Load(object sender, EventArgs e)
        {

            InitTable();
            BindWarehouse();
            if (this.LineItems.Rows.Count == 0)
            {
                gridView1.AddNewRow();
            }
        }

        private void gridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Down)
            {
                if (gridView1.IsLastRow)
                {
                    string sItemCode = "";
                    int iCount = gridView1.FocusedRowHandle;

                    sItemCode = gridView1.GetRowCellValue(iCount, gridView1.Columns["ItemCode"]).ToString();

                    if (sItemCode != "")
                    {
                        gridView1.AddNewRow();

                        gridView1.FocusedRowHandle = DevExpress.XtraGrid.GridControl.NewItemRowHandle;
                        gridView1.FocusedColumn = gridView1.VisibleColumns[0];
                        gridView1.ShowEditor();
                    }
                }
            }
        }
    }
}
